﻿//AcademicPlanner - course registration planning web app.
//Copyright (C) 2009  Boubacar Diallo

//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either version 2
//of the License, or (at your option) any later version.

//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.

//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace AcademicPlanner.Presentation
{
	/// <summary>
	/// Labels is a static class for storage and retrieval of labels (mostly form related).
	/// </summary>
	/// <version>1.0</version>
	/// <since>1.0</since>
	public static class Labels
	{
		private static Dictionary<string, string> labels;
		private static string separator = "_";

		private static void Init()
		{
			labels = new Dictionary<string, string>();

			labels.Add("User_Name", "Username");
			labels.Add("User_RepeatedPassword", "Repeat Password");
			labels.Add("AcademicPlan_CreditUnits", "Credit Units");
			labels.Add("AcademicTerm_OrderNum", "Position in Year");
			labels.Add("Program_MinimumCredits", "Minimum Credits");
			labels.Add("Program_RequiredCourses", "Required Courses");
			labels.Add("Program_RecommendedCourses", "Recommended Courses");
			labels.Add("Course_CommonlyOfferedInTerms", "Terms Commonly Offered");
			labels.Add("AcademicSchedule_StartYear", "Start Year");
			labels.Add("AcademicSchedule_StartTerm", "Start Term");
		}

		/// <summary>
		/// Gets the label text of a <code>Model</code>'s property.
		/// </summary>
		/// <param name="pProperty">The name of the property whose label to get.</param>
		/// <param name="pModel">The name of the <code>Model</code> the property belongs to.</param>
		/// <returns>The property's label; the property name if nothing was found
		/// in the storage.</returns>
		/// <version>1.0</version>
		/// <since>1.0</since>
		public static string Get(string pProperty, string pModel)
		{
			if (labels == null) Init();

			string rVal = pProperty;
			string vKey = string.IsNullOrEmpty(pModel) ? pProperty : pModel + separator + pProperty;

			labels.TryGetValue(vKey, out rVal);
			if (rVal == null) rVal = pProperty;

			return rVal;
		}

		/// <summary>
		/// Gets the label text of a property. This method is a convenience overload of
		/// <see cref="M:Get(string, string)"/> with the second parameter null.
		/// </summary>
		/// <param name="pProperty">The name of the property whose label to get.</param>
		/// <returns>The property's label.</returns>
		/// <version>1.0</version>
		/// <since>1.0</since>
		public static string Get(string pProperty)
		{
			return Get(pProperty, null);
		}
	}
}
